/**   
 * Copyright © 2016 北京之洲科技有限责任公司. All rights reserved.
 * 
 * @Title: PriceDaoOfAutoHome.java 
 * @Prject: carfactory
 * @Package: com.zizo.autohome.price.dao 
 * @Description: 
 * @author: Alexis  
 * @email heyan0227@outlook.com
 * @date: 2016年7月29日 下午4:50:37 
 * @version: V1.0   
 */
package com.zizo.autohome.price.dao;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

import com.zizo.autohome.price.bean.AutoHomePrice;
import com.zizo.core.DAO;
import com.zizo.core.T;
import com.zizo.util.Util;

/**
 * @ClassName: PriceDaoOfAutoHome
 * @Description:
 * @author: Alexis
 * @date: 2016年7月29日 下午4:50:37
 */
public class PriceDaoOfAutoHome extends DAO {

	/**
	 * @Title:PriceDaoOfAutoHome
	 * @Description:
	 * @param currConn
	 * @param coreConn
	 */
	public PriceDaoOfAutoHome(Connection currConn) {
		super(currConn);
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: getIDs
	 * 
	 * @Description:
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.DAOInterface#getIDs()
	 */
	@Override
	public List<String> getIDs() {
		List<String> carIDs = new ArrayList<>();
		Statement st = null;
		ResultSet rs = null;
		String sql = "SELECT brand_autohomeClubId FROM core_brand_autohome";
		try {
			st = coreConn.createStatement();
			rs = st.executeQuery(sql);
			while (rs.next()) {
				carIDs.add(rs.getInt(1) + "");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return carIDs;
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: insertData
	 * 
	 * @Description:
	 * 
	 * @param t
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.DAOInterface#insertData(com.zizo.core.T)
	 */
	@Override
	public int insertData(T t) {
		AutoHomePrice price = (AutoHomePrice) t;
		PreparedStatement ps = null;
		String sql = "REPLACE INTO autohome_other.other_price(price_cid,price_mid,price_uid,price_rz,price_ptime,price_lcj,price_zdj,price_gzs,price_sybx,price_hjjg,price_spfy,price_ccsy,price_jqx,price_cxtc,price_btime,price_province,price_area,price_4s,price_gmpj,price_gmgs,price_uptime,price_lspz,price_dkfy,price_yb,price_fqsx,price_dj,price_fwf,price_ajfy,price_ajlx,price_xh,price_zs,price_zsm,price_wlyq,price_dksxf,price_id,price_istrue) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		try {
			ps = currConn.prepareStatement(sql);
			ps.setInt(1, price.getPrice_ppid());
			ps.setInt(2, price.getPrice_cxid());
			ps.setInt(3, price.getPrice_yhid());
			ps.setInt(4, price.getPrice_rz());
			ps.setDate(5, (Date) Util.getDate(price.getPrice_fbsj()));
			ps.setDouble(6, price.getPrice_lcj());
			ps.setDouble(7, price.getPrice_zdj());
			ps.setDouble(8, price.getPrice_gzs());
			ps.setDouble(9, price.getPrice_sybx());
			ps.setDouble(10, price.getPrice_hjjg());
			ps.setDouble(11, price.getPrice_spfy());
			ps.setDouble(12, price.getPrice_ccsy());
			ps.setDouble(13, price.getPrice_jqx());
			ps.setString(14, price.getPrice_cxtc());
			ps.setDate(15, (Date) Util.getDate(price.getPrice_gcsj()));
			ps.setString(16, price.getPrice_gcsf());
			ps.setString(17, price.getPrice_gcds());
			ps.setInt(18, price.getPrice_gmsj());
			ps.setString(19, price.getPrice_gmpj());
			ps.setString(20, price.getPrice_gmgs());
			ps.setTimestamp(21, (Timestamp) Util.getTimeHMS(Util.getCurrentDateTime()));
			ps.setDouble(22, price.getPrice_lspz());
			ps.setDouble(23, price.getPrice_dkfy());
			ps.setDouble(24, price.getPrice_yb());
			ps.setDouble(25, price.getPrice_fqsx());
			ps.setDouble(26, price.getPrice_dj());
			ps.setDouble(27, price.getPrice_fwf());
			ps.setDouble(28, price.getPrice_ajfy());
			ps.setDouble(29, price.getPrice_ajlx());
			ps.setDouble(30, price.getPrice_xh());
			ps.setDouble(31, price.getPrice_zs());
			ps.setDouble(32, price.getPrice_zsm());
			ps.setDouble(33, price.getPrice_wlyq());
			ps.setDouble(34, price.getPrice_dksxf());
			ps.setInt(35, price.getPrice_id());
			int istrue = 0;
			if (price.getPrice_lcj() >= price.getPrice_zdj() * 0.7
					&& price.getPrice_lcj() <= price.getPrice_zdj() * 1.2) {
				istrue = 1;
			}
			ps.setInt(36, istrue);
			ps.executeUpdate();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return 0;
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: updateTime
	 * 
	 * @Description:
	 * 
	 * @param type
	 * 
	 * @param id
	 * 
	 * @see com.zizo.core.DAOInterface#updateTime(java.lang.String,
	 * java.lang.String)
	 */
	@Override
	public void updateTime(String type, String id) {
		// TODO Auto-generated method stub

	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: getTables
	 * 
	 * @Description:
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.DAOInterface#getTables()
	 */
	@Override
	public List<String> getTables() {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non Javadoc)
	 * 
	 * @Title: insertError
	 * 
	 * @Description:
	 * 
	 * @param t
	 * 
	 * @return
	 * 
	 * @see com.zizo.core.DAOInterface#insertError(com.zizo.core.T)
	 */
	@Override
	public int insertError(T t) {
		return 0;
	}

}
